from rosa.love_is_blue.backend.memory.memory_crud import MemoryCRUDRouter
from rosa.rosa_apps.memory_apps.types import UserQueryData, UserCreateData, UserUpdateData, AuthData
from rosa.scarborough_fair import BaseResponse

router = MemoryCRUDRouter(
    UserQueryData,
    UserCreateData,
    UserUpdateData,
    prefix="/api/admin/user",
    tags=["用户管理-memory"]
)


@router.post("/auth", response_model=UserQueryData, summary="用户登录")
async def auth(data: AuthData):
    """
    用户登录
    \f
    :param data: 用户登录信息
    :return:
    """
    for model in router.models:
        if model.username == data.username and model.password == data.password:
            data = model.model_dump()
            break
    else:
        data = dict()

    return BaseResponse(data=data)
